/**
 * @author NingZB
 * @version 1.0.0 beta
 */
YUI.namespace('IRMAjax')
YUI.add('irm-ajax',function(Y){
	Y.IRMAjax = function(){
		this.init.apply(this,arguments);
	}
	Y.IRMAjax.prototype = {
		init: function(config){
			var that = this;
			that.buildParam(config);
			that.render();
		},
		buildParam: function(config){
			var that = this;
			config = config || {};
			that.node = config.node;
			that.con = config.con || null;
			that.beforeNode = config.beforeNode || null;
			that.url = config.url || '';
			that.method = config.method || 'GET';
			that.sendData = config.sendData || '';
			that.timeout = config.timeout || 5000;
			that.sendHeader = config.sendHeader || '';
			that.afterAjax = config.afterAjax || function(){};
			return this;
		},
		render: function(){
			var that = this;
			that.responseHTML = null;
			that.transaction();
			return this;			
		},
		transaction: function(){
			var that = this;
			Y.io(that.url,{
				method: that.method,
				data: that.sendData,
				header: that.sendHeader,
				on: {
					start: function(id){
						that.loading = Y.Node.create('<div class="irmajax-loading"></div>');
						that.loading.setStyle('opacity','0.2');
						that.con.appendChild(that.loading);
					},
					complete: function(id,o){
						that.responseHTML = o.responseText;
					},
					success: function(id,o){
						that.loading.remove();
						that.loading = null;
						that.con.insertBefore(Y.Node.create(that.responseHTML),that.beforeNode);
						that.con.addClass('show');
					},
					fail: function(id,o){
						
					},
					end: function(id){

					}
				},
				timeout: that.timeout
			})
			return this;
		}
	}
},'1.0.0',{requires:['node','io']})
